/*     */ package com.lmpop.trade.backupDB;
/*     */ 
/*     */ import com.lmpop.frame.QueryList;
/*     */ import com.lmpop.frame.SysMap;
/*     */ import com.lmpop.frame.dao.DbmInterf;
/*     */ import com.lmpop.frame.util.Config;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintStream;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Hashtable;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.StringTokenizer;
/*     */ 
/*     */ public class Backup
/*     */ {
/*     */   QueryList queryList;
/*  19 */   ArrayList queryResult = new ArrayList();
/*     */ 
/*     */   public Backup() {
/*  22 */     this.queryList = new QueryList();
/*     */   }
/*     */   public ArrayList getQueryResult() {
/*  25 */     return this.queryResult;
/*     */   }
/*     */ 
/*     */   public void setQueryResult(ArrayList queryResult) {
/*  29 */     this.queryResult = queryResult;
/*     */   }
/*     */ 
/*     */   public SysMap backupTable(DbmInterf dbmMgr, SysMap map)
/*     */     throws IOException
/*     */   {
/*  36 */     Config cfg = new Config("jdbc.properties");
/*  37 */     System.out.println("-------------backupTable---------->");
/*  38 */     String result_code = "0";
/*  39 */     String tableName = map.getString("table_name");
/*  40 */     String dbName = cfg.getString("dbname");
/*  41 */     if (tableName.equals("")) {
/*  42 */       tableName = dbName;
/*     */     }
/*  44 */     StringTokenizer st = new StringTokenizer(tableName, "|");
/*     */     try {
/*  46 */       while (st.hasMoreElements()) {
/*  47 */         String t_n = st.nextToken();
/*  48 */         DataMgr dataMgr = new DataMgr();
/*  49 */         dataMgr.backup(t_n);
/*     */       }
/*     */     } catch (Exception e) {
/*  52 */       e.printStackTrace();
/*  53 */       result_code = "1";
/*     */     }
/*  55 */     map.setString("result_code", result_code);
/*  56 */     return map;
/*     */   }
/*     */ 
/*     */   public SysMap restoreTable(DbmInterf dbmMgr, SysMap map)
/*     */     throws IOException
/*     */   {
/*  65 */     System.out.println("-------------restoreTable---------->");
/*  66 */     String result_code = "0";
/*  67 */     String tableName = map.getString("table_name");
/*  68 */     StringTokenizer st = new StringTokenizer(tableName, "|");
/*     */     try {
/*  70 */       while (st.hasMoreElements()) {
/*  71 */         String t_n = st.nextToken();
/*  72 */         DataMgr dataMgr = new DataMgr();
/*  73 */         dataMgr.restore(t_n);
/*     */       }
/*     */     } catch (Exception e) {
/*  76 */       e.printStackTrace();
/*  77 */       result_code = "1";
/*     */     }
/*  79 */     map.setString("result_code", result_code);
/*  80 */     return map;
/*     */   }
/*     */ 
/*     */   public SysMap restoreDatabase(DbmInterf dbmMgr, SysMap map)
/*     */     throws IOException
/*     */   {
/*  87 */     String result_code = "0";
/*  88 */     String backup_dbname = map.getString("BACKUP_DBNAME");
/*     */     try {
/*  90 */       DataMgr dataMgr = new DataMgr();
/*  91 */       dataMgr.restore(backup_dbname);
/*     */     } catch (Exception e) {
/*  93 */       e.printStackTrace();
/*  94 */       result_code = "1";
/*     */     }
/*  96 */     map.setString("result_code", result_code);
/*  97 */     return map;
/*     */   }
/*     */ 
/*     */   public int selAllTableCounts(String dbName) {
/* 101 */     List list = this.queryList.getList("selAllTableCountsBackup", dbName);
/* 102 */     int count = 0;
/* 103 */     if ((list != null) && (list.size() > 0)) {
/* 104 */       Hashtable newsMap = (Hashtable)list.get(0);
/* 105 */       if ((newsMap.get("count") != null) && (!newsMap.get("count").toString().equals(""))) {
/* 106 */         count = Integer.parseInt(newsMap.get("count").toString());
/*     */       }
/*     */     }
/* 109 */     return count;
/*     */   }
/*     */ 
/*     */   public List selAllTableInfo(String dbName, int start, int limit)
/*     */   {
/* 118 */     Map params = new Hashtable();
/* 119 */     if (start == 0)
/* 120 */       start = 0;
/*     */     else {
/* 122 */       start = (start - 1) * limit;
/*     */     }
/* 124 */     params.put("start", Integer.valueOf(start));
/* 125 */     params.put("limit", Integer.valueOf(limit));
/*     */ 
/* 127 */     params.put("dbName", dbName);
/*     */ 
/* 129 */     List resultList = new ArrayList();
/* 130 */     resultList = this.queryList.getList("getAllTablesBackup", params);
/* 131 */     for (int i = 0; i < resultList.size(); i++) {
/* 132 */       Hashtable map = (Hashtable)resultList.get(i);
/* 133 */       String table_name = "";
/*     */ 
/* 135 */       String count = "0";
/*     */ 
/* 137 */       if (map.get("table_name") != null)
/*     */       {
/* 139 */         table_name = map.get("table_name").toString();
/* 140 */         params.put("table_name", table_name);
/* 141 */         List list = this.queryList.getList("getTableElementsCount", params);
/* 142 */         if ((list != null) && (list.size() > 0)) {
/* 143 */           Hashtable newsMap = (Hashtable)list.get(0);
/* 144 */           if ((newsMap.get("count") != null) && (!newsMap.get("count").toString().equals(""))) {
/* 145 */             count = newsMap.get("count").toString();
/*     */           }
/*     */         }
/*     */       }
/* 149 */       map.put("table_size", count);
/*     */     }
/* 151 */     return resultList;
/*     */   }
/*     */ 
/*     */   public List selTableStructure(String table_name)
/*     */   {
/* 161 */     Map params = new Hashtable();
/* 162 */     params.put("table_name", table_name);
/* 163 */     List resultList = this.queryList.getList("getTableStructure", params);
/* 164 */     return resultList;
/*     */   }
/*     */ }

/* Location:           F:\电商\commons-utils.jar
 * Qualified Name:     com.lmpop.trade.backupDB.Backup
 * JD-Core Version:    0.6.0
 */